<?php 
class siteView extends C_view
{
	function siteView()
	{
		parent::C_view();
	}
	function display($tpl)
	{		
		$SYS = &get_instance();
		if($SYS->config->item('offline') == 1) 
		{
			
			parent::display('offline',PATH_THEMES.DS.'sites'.DS.$SYS->config->item('sitetheme'));
			exit();
		}
		$form=$SYS->request->getVar('form',null,'get');
		$tpl = $form==null?$tpl:'form';
		$this->assignRef('title', $this->get('Title'));
		switch($tpl)
		{
			case 'error':
					$this->assignRef('message', $SYS->loader->getMessageQueue());
					C_html::stylesheet('metinfo.css',WEBURL.'/templates/sites/'.'default'.'/css/');
					$this->assignRef( 'lang', $this->get('Language'));
					parent::display('error',PATH_THEMES.DS.'sites'.DS.$SYS->config->item('sitetheme'));break;
			case 'form':
					C_HTML::_('behavior.mootools');
					$this->assignRef( 'form', $this->get('Form'));
					$this->assign( 'imgpath', WEBURL.'/templates/forms/'.$this->form['theme'].'/images');
					$this->assign( 'csspath', WEBURL.'/templates/forms/'.$this->form['theme'].'/css');
					C_html::stylesheet('metinfo.css',$this->csspath.'/');
					$this->assignRef( 'lang', $this->get('Language'));
					$this->assignRef( 'questions', $this->get('Questions'));
					$this->assignRef( 'answers', $this->get('Answers'));					
					$this->assignRef('namefield', $this->get('Name'));
					$this->assignRef('introducefield', $this->get('Introduce'));
					$this->assignRef('onlinelist', $this->get('Online'));					
					$SYS->doc->addScriptDeclaration($this->validateSite());
					parent::display('form',PATH_THEMES.DS.'forms'.DS.$this->form['theme']);break;
			default:
					$this->assignRef( 'lang', $this->get('Language'));
					C_html::stylesheet('metinfo.css',WEBURL.'/templates/sites/'.$SYS->config->item('sitetheme').'/css/');
					$this->assignRef( 'forms', $this->get('Forms'));
					parent::display('site',PATH_THEMES.DS.'sites'.DS.$SYS->config->item('sitetheme'));
		}
	}
	function validateSite()
	{
		$jscontent = 
		"
		function validate() {
			var name;
			var num=0;
			var begin=true;
			var flag=false;
			var ret=true;
			$$('.must').each(function(el) {
				if(begin) name=el.get('name');
				begin=false;
				if(name!=el.get('name'))
				{
					if(flag && num==0)
					{						
						ret=false;
					}
					flag=false;
					num=0;
				}
				if(el.get('type')=='checkbox')
				{
					flag=true;
					if(el.get('checked'))	num = num+1;
				}
				if(el.get('type')=='radio')
				{
					flag=true;
					if(el.get('checked'))	num = num+1;
				}
				if(el.get('type')!='radio' || el.get('type')!='checkbox')
				{
					if(el.get('value')=='' || el.get('value')=='- ".C_text::_('SelectType')." -')
					{
						ret=false;
					}
				}
				name=el.get('name');
			});
			if(flag && num==0)
			{						
				ret=false;
			}
			if(!ret)
			{
				alert('".C_text::_('Must')."');
				return 0;
			}
			document.siteform.task.value = 'save';
			document.siteform.submit();
		};		
		
		";
		return $jscontent;
	}
}
?>